// publish/common/InputArea.js
const app = getApp();
Component({
  properties: {
    wename:{
       type:String
     },
     tail:{
      type:String
     },  
     placeholder:{
      type:String
     },  
     val:{
      type:String
     },  
     target:{
      type:String,
      value:'tmp',
    },
     decimal:{
       type:Number,
       value:2,
     }
  },
  data: {
     value:'',
     type:1,
  },
  attached(){
    var type = this.data.type 
    if(this.properties.tail =='元-m-月') type=-1;
    if(this.properties.tail =='m') type=-2;
    this.setData({  value:this.properties.val,type})
  },
  methods: { 
    setValue(e){
      let value = this.validateNumber(e.detail.value)
      console.log(value,this.properties);
      if(value=='') value = 0;
      value = parseFloat(value).toFixed(this.properties.decimal) 
      this.setData({  value  })
      app.globalData[this.properties.target][this.properties.wename] = value 
    },
    validateNumber(val) {
       return val.replace(/\D/g, '')
    },
  }
})
